import dayjs from 'dayjs'
import 'dayjs/locale/zh' // 集成中文
// import customParseFormat from 'dayjs/plugin/customParseFormat'
// 获取的后台数据转化周
export const getWeekZh = (time) => {
  time = new Date(time).getDay()
  let week = ''
  switch (time) {
    case 0:
      week = '星期天'
      break
    case 1:
      week = '星期一'
      break
    case 2:
      week = '星期二'
      break
    case 3:
      week = '星期三'
      break
    case 4:
      week = '星期四'
      break
    case 5:
      week = '星期五'
      break
    case 6:
      week = '星期六'
      break
  }
  return week
}
// 格式化月份
export const getMonthZh = (item) => {
  return `${dayjs(item).format('MM')}月${dayjs(item).format('DD')}日`
}
// 格式化年
export const getYearZh = (item) => {
  return `${dayjs(item).format('YYYY')}年${dayjs(item).format('MM')}月`
}
// 需要传参的日期格式化
// 当前日期
export const getCurrentDay = () => {
  return dayjs().format('YYYY-MM-DD')
}
// 相对当前日期的周一
export const getWeek = () => {
  const date = new Date()
  const year = date.getFullYear() // 22
  const month = date.getMonth() // 10
  const day = date.getDate() // 17
  const week = date.getDay() // 1
  const weekStart = new Date(year, month, day - week + 1)
  return dayjs(weekStart).format('YYYY-MM-DD')
}
// 相对当前日期的月份第一天
export const getMonth = () => {
  return dayjs().startOf('month').format('YYYY-MM-DD')
}
// 相对当前日期的月份第一天
export const getyYear = () => {
  return dayjs().startOf('year').format('YYYY-MM-DD')
}
